﻿using System;
using System.Collections.Generic;
using BoutiquePOS.DAL.DAO;
using BoutiquePOS.DAL.Gateway;

namespace BoutiquePOS.Manager
{
    public class CompanyManager
    {
        CompanyGateway companyGateway = new CompanyGateway();
        public string SaveCompany(Company company)
        {
            if (!DoesThisCompanyExist(company))
                return companyGateway.SaveCompany(company);
            else
            {
                return "This Company Already Exists";
            }
        }
        private bool DoesThisCompanyExist(Company company)
        {
            try
            {
                List<Company> companies = new List<Company>();
                companies = GetAllCompany();

                foreach (Company companyObj in companies)
                {
                    if (companyObj.CompanyName == company.CompanyName)
                        return true;
                }
                return false;
            }
            catch (Exception)
            {              
                throw;
            }
           
        }
        public List<Company> GetAllCompany()
        {
            return companyGateway.GetAllCompany();
        }

        public List<Company> GetAllCompanyByIdOrName(int i, string Id)
        {
            return companyGateway.GetAllCompanyByCodeOrName(i,Id);
        }
        public string DeleteCompany(int companyId)
        {
            string message = companyGateway.DeleteCompanyById(companyId);
            return message;
        }
    }
}